﻿using System;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace DataAccess
{
    public class NhapKhoDAO
    {
        private static readonly String URL = ConfigurationSettings.AppSettings["Main.ConnectionString"];
        public NhapKhoDAO()
        {

        }

        public static DataSet GetAll()
        {
            return SqlHelper.ExecuteDataset(URL, CommandType.Text, "SELECT * FROM NhapKho");
        }

        public static void Delete(int id) 
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@MaNhapKho", id);
            SqlHelper.ExecuteNonQuery(URL, CommandType.Text, "DELETE FROM NhapKho WHERE MaNhapKho = @MaNhapKho", sqlParameter);
        }

        public static void Insert(double tongtien,string masanpham,string tensanpham,int soluong,double giasanpham,double vat,int manhacungcap,string ghichu,int madonvi,string ngaynhap,
            int manhanvien,int manhomsanpham,int hoadon)
        {
            SqlParameter[] sqlParameter = new SqlParameter[13];
            sqlParameter[0] = new SqlParameter("@TongTien", tongtien);
            sqlParameter[1] = new SqlParameter("@MaSanPham", masanpham);
            sqlParameter[2] = new SqlParameter("@TenSanPham", tensanpham);
            sqlParameter[3] = new SqlParameter("@SoLuong", soluong);
            sqlParameter[4] = new SqlParameter("@GiaSanPham", giasanpham);
            sqlParameter[5] = new SqlParameter("@VAT", vat);
            sqlParameter[6] = new SqlParameter("@MaNhaCungCap", manhacungcap);
            sqlParameter[7] = new SqlParameter("@MaNhomSanPham", manhomsanpham);
            sqlParameter[8] = new SqlParameter("@MaDonVi", madonvi);
            sqlParameter[9] = new SqlParameter("@GhiChu", ghichu);
            sqlParameter[10] = new SqlParameter("@MaNhanVien", manhanvien);
            sqlParameter[11] = new SqlParameter("@NgayNhap", DateUtil.convertStringToDate2(ngaynhap));
            sqlParameter[12] = new SqlParameter("@HoaDon", hoadon);
            SqlHelper.ExecuteNonQuery(URL, CommandType.StoredProcedure, "INSERT_NHAP_KHO", sqlParameter);
        }

        public static void Update(int id,string name,int value)
        {
            
        }
        public static DataSet GetBy(int id)
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@MaNhapKho", id);
            return SqlHelper.ExecuteDataset(URL, CommandType.Text, "SELECT * FROM NhapKho WHERE MaNhapKho = @MaNhapKho", sqlParameter);
        }
    }
}
